package com.wpzf.ndhc.controller;

import com.wpzf.common.core.utils.ServletUtils;
import com.wpzf.common.core.web.domain.AjaxResult;
import com.wpzf.common.log.annotation.Log;
import com.wpzf.common.log.enums.BusinessType;
import com.wpzf.common.security.service.TokenService;
import com.wpzf.ndhc.domain.WpCjTbhcjgDTO;
import com.wpzf.ndhc.service.WpzfNdhcZgTbTaskService;
import com.wpzf.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/wpzfndhcZgTbTask")
public class WpzfNdhcZgTbTaskController {

    @Autowired
    WpzfNdhcZgTbTaskService wpzfNdhcZgTbTaskService;

    @Autowired
    TokenService tokenService;

    @Value("${tempath}")
    public String tempath;

    /*图斑整改*/
    @RequestMapping(value = "/zgSubmit", method = RequestMethod.POST)
    public AjaxResult zgSubmit(@RequestBody Map<String, Object> parms) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        parms.put("sh_username", loginUser.getUsername());
        parms.put("sh_realname", loginUser.getSysUser().getNickName());
        Integer rest = wpzfNdhcZgTbTaskService.zgSubmit(parms);
        if (rest > 0) {
            return AjaxResult.success("图斑整改成功", rest);
        }
        return AjaxResult.error("图斑整改失败", -1);
    }

    @Log(title ="获取整改批次号 *****************核查单位人员",businessType = BusinessType.OTHER)
    @RequestMapping(value = "/query_unit_zgtb_pch", method = RequestMethod.POST)
    public AjaxResult query_unit_zgtb_pch(@RequestBody Map<String, Object> parms) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        parms.put("username", loginUser.getUsername());
        parms.put("dwmc", loginUser.getSysUser().getDept().getDeptName());
        List<Map<String, Object>> rest = wpzfNdhcZgTbTaskService.query_unit_zgtb_pch(parms);
        if (rest != null) {
            return AjaxResult.success("批次号获取成功", rest);
        }
        return AjaxResult.error("批次号获取失败", -1);
    }

    @Log(title ="获取所有待整改的图斑 *****************核查单位人员",businessType = BusinessType.OTHER)
    @RequestMapping(value = "/query_unit_user_dzgtb_list", method = RequestMethod.POST)
    public AjaxResult query_unit_user_dzgtb_list(@RequestBody Map<String, Object> parms) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        parms.put("username", loginUser.getUsername());
        parms.put("dwmc", loginUser.getSysUser().getDept().getDeptName());
        List<Map<String, Object>> rest = wpzfNdhcZgTbTaskService.query_unit_user_dzgtb_list(parms);
        Integer cnt = wpzfNdhcZgTbTaskService.query_unit_user_dzgtb_list_count(parms);
        if (rest != null) {
            return AjaxResult.success("获取所有待整改的图斑成功", rest,cnt);
        }
        return AjaxResult.error("获取所有待整改的图斑失败", -1);
    }

    @Log(title ="获取所有待整改的图斑左侧列表 *****************核查单位人员",businessType = BusinessType.OTHER)
    @RequestMapping(value = "/query_unit_user_dzgtb_leftlist", method = RequestMethod.POST)
    public AjaxResult query_unit_user_dzgtb_leftlist(@RequestBody Map<String, Object> parms) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        parms.put("username", loginUser.getUsername());
        parms.put("dwmc", loginUser.getSysUser().getDept().getDeptName());
        List<Map<String, Object>> rest = wpzfNdhcZgTbTaskService.query_unit_user_dzgtb_leftlist(parms);
        if (rest != null) {
            return AjaxResult.success("获取所有待整改的图斑成功", rest);
        }
        return AjaxResult.error("获取所有待整改的图斑失败", -1);
    }

    @Log(title ="获取所有已整改的图斑*****************核查单位",businessType = BusinessType.OTHER)
    @RequestMapping(value = "/query_unit_user_yzgtb_list", method = RequestMethod.POST)
    public AjaxResult query_unit_user_yzgtb_list(@RequestBody Map<String, Object> parms) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        parms.put("username", loginUser.getUsername());
        parms.put("dwmc", loginUser.getSysUser().getDept().getDeptName());
        List<Map<String, Object>> rest = wpzfNdhcZgTbTaskService.query_unit_user_yzgtb_list(parms);
        Integer cnt = wpzfNdhcZgTbTaskService.query_unit_user_yzgtb_list_count(parms);
        if (rest != null) {
            return AjaxResult.success("获取所有已整改的图斑成功", rest,cnt);
        }
        return AjaxResult.error("获取所有已整改的图斑失败", -1);
    }

    @Log(title ="获取所有已整改的图斑左侧列表*****************核查单位",businessType = BusinessType.OTHER)
    @RequestMapping(value = "/query_unit_user_yzgtb_leftlist", method = RequestMethod.POST)
    public AjaxResult query_unit_user_yzgtb_leftlist(@RequestBody Map<String, Object> parms) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        parms.put("username", loginUser.getUsername());
        parms.put("dwmc", loginUser.getSysUser().getDept().getDeptName());
        List<Map<String, Object>> rest = wpzfNdhcZgTbTaskService.query_unit_user_yzgtb_leftlist(parms);
        if (rest != null) {
            return AjaxResult.success("获取所有已整改的图斑成功", rest);
        }
        return AjaxResult.error("获取所有已整改的图斑失败", -1);
    }

    @Log(title ="获取整改批次号 *****************核查单位负责人",businessType = BusinessType.OTHER)
    @RequestMapping(value = "/query_unit_pch", method = RequestMethod.POST)
    public AjaxResult query_unit_pch(@RequestBody Map<String, Object> parms) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        parms.put("username", loginUser.getUsername());
        parms.put("dwmc", loginUser.getSysUser().getDept().getDeptName());
        List<Map<String, Object>> rest = wpzfNdhcZgTbTaskService.query_unit_pch(parms);
        if (rest != null) {
            return AjaxResult.success("批次号获取成功", rest);
        }
        return AjaxResult.error("批次号获取失败", -1);
    }

    @Log(title ="获取所有待整改的图斑 *****************核查单位负责人",businessType = BusinessType.OTHER)
    @RequestMapping(value = "/query_unit_dzgtb_list", method = RequestMethod.POST)
    public AjaxResult query_unit_dzgtb_list(@RequestBody Map<String, Object> parms) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        parms.put("username", loginUser.getUsername());
        parms.put("dwmc", loginUser.getSysUser().getDept().getDeptName());
        List<Map<String, Object>> rest = wpzfNdhcZgTbTaskService.query_unit_dzgtb_list(parms);
        int cnt=wpzfNdhcZgTbTaskService.query_unit_dzgtb_list_count(parms);
        if (rest != null) {
            return AjaxResult.success("获取所有待整改的图斑成功", rest,cnt);
        }
        return AjaxResult.error("获取所有待整改的图斑失败", -1);
    }

    @Log(title ="获取所有已整改的图斑 *****************核查单位负责人",businessType = BusinessType.OTHER)
    @RequestMapping(value = "/query_unit_yzgtb_list", method = RequestMethod.POST)
    public AjaxResult query_unit_yzgtb_list(@RequestBody Map<String, Object> parms) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        parms.put("username", loginUser.getUsername());
        parms.put("dwmc", loginUser.getSysUser().getDept().getDeptName());
        List<Map<String, Object>> rest = wpzfNdhcZgTbTaskService.query_unit_yzgtb_list(parms);
        int cnt=wpzfNdhcZgTbTaskService.query_unit_yzgtb_list_count(parms);
        if (rest != null) {
            return AjaxResult.success("获取所有已整改的图斑成功", rest,cnt);
        }
        return AjaxResult.error("获取所有已整改的图斑失败", -1);
    }

    @Log(title ="当前图斑进行整改",businessType = BusinessType.OTHER)
    @RequestMapping(value = "/update_unit_zgtb", method = RequestMethod.POST)
    public AjaxResult update_unit_zgtb(@RequestBody Map<String, Object> parms) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        parms.put("username", loginUser.getUsername());
        parms.put("realname", loginUser.getSysUser().getNickName());
        parms.put("dwmc", loginUser.getSysUser().getDept().getDeptName());
        int rest=wpzfNdhcZgTbTaskService.update_unit_zgtb(parms);
        if (rest>0) {
            return AjaxResult.success("整改图斑成功", rest);
        }
        return AjaxResult.error("整改图斑失败", -1);
    }

    @Log(title ="获取整改批次号 *****************监理人员",businessType = BusinessType.OTHER)
    @RequestMapping(value = "/query_jl_zgtb_pch", method = RequestMethod.POST)
    public AjaxResult query_jl_zgtb_pch(@RequestBody Map<String, Object> parms) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        parms.put("username", loginUser.getUsername());
        parms.put("dwmc", loginUser.getSysUser().getDept().getDeptName());
        List<Map<String, Object>> rest = wpzfNdhcZgTbTaskService.query_jl_zgtb_pch(parms);
        if (rest != null) {
            return AjaxResult.success("监理人员批次号获取成功", rest);
        }
        return AjaxResult.error("监理人员批次号获取失败", -1);
    }

    @Log(title ="获取所有待整改的图斑 *****************监理人员",businessType = BusinessType.OTHER)
    @RequestMapping(value = "/query_jl_user_dzgtb_list", method = RequestMethod.POST)
    public AjaxResult query_jl_user_dzgtb_list(@RequestBody Map<String, Object> parms) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        parms.put("username", loginUser.getUsername());
        parms.put("dwmc", loginUser.getSysUser().getDept().getDeptName());
        List<Map<String, Object>> rest = wpzfNdhcZgTbTaskService.query_jl_user_dzgtb_list(parms);
        Integer cnt = wpzfNdhcZgTbTaskService.query_jl_user_dzgtb_list_count(parms);
        if (rest != null) {
            return AjaxResult.success("获取所有待整改的图斑成功", rest,cnt);
        }
        return AjaxResult.error("获取所有待整改的图斑失败", -1);
    }

    @Log(title ="获取所有待整改的图斑左侧列表 *****************监理人员",businessType = BusinessType.OTHER)
    @RequestMapping(value = "/query_jl_user_dzgtb_leftlist", method = RequestMethod.POST)
    public AjaxResult query_jl_user_dzgtb_leftlist(@RequestBody Map<String, Object> parms) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        parms.put("username", loginUser.getUsername());
        parms.put("dwmc", loginUser.getSysUser().getDept().getDeptName());
        List<Map<String, Object>> rest = wpzfNdhcZgTbTaskService.query_jl_user_dzgtb_leftlist(parms);
        if (rest != null) {
            return AjaxResult.success("获取所有待整改的图斑左侧列表 成功", rest);
        }
        return AjaxResult.error("获取所有待整改的图斑左侧列表 失败", -1);
    }

    @Log(title ="获取所有已整改的图斑 *****************监理人员",businessType = BusinessType.OTHER)
    @RequestMapping(value = "/query_jl_user_yzgtb_list", method = RequestMethod.POST)
    public AjaxResult query_jl_user_yzgtb_list(@RequestBody Map<String, Object> parms) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        parms.put("username", loginUser.getUsername());
        parms.put("dwmc", loginUser.getSysUser().getDept().getDeptName());
        List<Map<String, Object>> rest = wpzfNdhcZgTbTaskService.query_jl_user_yzgtb_list(parms);
        Integer cnt = wpzfNdhcZgTbTaskService.query_jl_user_yzgtb_list_count(parms);
        if (rest != null) {
            return AjaxResult.success("获取所有已整改的图斑成功", rest,cnt);
        }
        return AjaxResult.error("获取所有已整改的图斑失败", -1);
    }

    @Log(title ="获取所有已整改的图斑 *****************监理人员",businessType = BusinessType.OTHER)
    @RequestMapping(value = "/query_jl_user_yzgtb_leftlist", method = RequestMethod.POST)
    public AjaxResult query_jl_user_yzgtb_leftlist(@RequestBody Map<String, Object> parms) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        parms.put("username", loginUser.getUsername());
        parms.put("dwmc", loginUser.getSysUser().getDept().getDeptName());
        List<Map<String, Object>> rest = wpzfNdhcZgTbTaskService.query_jl_user_yzgtb_leftlist(parms);
        if (rest != null) {
            return AjaxResult.success("获取所有已整改的图斑成功", rest);
        }
        return AjaxResult.error("获取所有已整改的图斑失败", -1);
    }

    //整改图斑回显
    @Log(title ="整改图斑回显",businessType = BusinessType.OTHER)
    @RequestMapping(value = "/queryZgtb", method = RequestMethod.POST)
    public AjaxResult queryZgtb(@RequestBody Map<String, Object> parm) {
        WpCjTbhcjgDTO rest = wpzfNdhcZgTbTaskService.queryZgtb(parm);
        if (rest != null) {
            return AjaxResult.success("整改图斑回显 成功", rest);
        }
        return AjaxResult.error("整改图斑回显 失败", -1);
    }












    //todo 整改
    @RequestMapping(value = "/getPch", method = RequestMethod.POST)
    public AjaxResult getPch(@RequestBody Map<String, Object> param) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        param.put("user_name", loginUser.getSysUser().getUserName());
        List<Map<String, Object>> rest = wpzfNdhcZgTbTaskService.getPch(param);
        return AjaxResult.success("获取批次号", rest);
    }

    //筛选条件查询接口（省、县）
    @RequestMapping(value = "/getSheng", method = RequestMethod.POST)
    public AjaxResult getSheng(@RequestBody Map<String, Object> param) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        param.put("user_name", loginUser.getSysUser().getUserName());
        List<Map<String, Object>> rest = wpzfNdhcZgTbTaskService.getSheng(param);
        return AjaxResult.success("获取省", rest);
    }

    @RequestMapping(value = "/getXian", method = RequestMethod.POST)
    public AjaxResult getXian(@RequestBody Map<String, Object> param) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        param.put("user_name", loginUser.getSysUser().getUserName());
        List<Map<String, Object>> rest = wpzfNdhcZgTbTaskService.getXian(param);
        return AjaxResult.success("获取县", rest);
    }

    //查询未完成、已完成地块列表接口，查询区县内未完成的图斑
    @RequestMapping(value = "/queryDkTask", method = RequestMethod.POST)
    public AjaxResult queryDkTask(@RequestBody Map<String, Object> param) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        param.put("user_name", loginUser.getSysUser().getUserName());
        List<Map<String, Object>> rest = wpzfNdhcZgTbTaskService.queryDkTask(param);
        Integer cnt = wpzfNdhcZgTbTaskService.queryDkTaskCount(param);
        return AjaxResult.success("地块列表", rest, cnt);
    }

    //整改任务提交
    @RequestMapping(value = "/submitdate", method = RequestMethod.POST)
    public AjaxResult submitdate(@RequestBody List<Map<String, Object>> params) {
        Integer rest = wpzfNdhcZgTbTaskService.submitdate(params);
        if (rest > 0) {
            return AjaxResult.success("整改任务提交 成功", rest);
        } else {
            return AjaxResult.error("整改任务提交 失败", rest);
        }
    }

}
